<?php
class Personel_Model {
	/**
	 * Holds instance of database connection
	 */
	private $db;
	private $page_data = array();
	private $lowerlevel_staff_content;
	
	public function __construct()
	{
		$this->db = new MysqlImproved_Driver;
	}
	
	public function get_personel($people){
		$this->db->connect();
		$this->get_page_data();
		$article['page_title'] = $this->page_data['title'];
		$article['page_description'] = $this->page_data['description'];
		$article['personel_content'] = $this->get_the_data_of_personel($people);
		$article['description'] = $this->get_personel_description($people);
		$article['keywords'] = $this->get_personel_keywords($people);
		return $article;
	}
	
	public function get_the_data_of_personel($people){
		// prepare query
		$people = $this->db->escape($people);
		$this->db->prepare(
				"
				SELECT
				`staff_link`,
				`staff_name`,
				`staff_email`,
				`staff_position`,
				`staff_description`,
				`staff_content`
				FROM
				`lowerlevel_staff`
				WHERE
				`staff_link` = '$people'
				LIMIT
				1
				;
				"
		);
		$this->db->query();
		$this->lowerlevel_staff_content = "";
		while($staff_data = $this->db->fetch('array')){
			$this->lowerlevel_staff_content .= "
				<div id=\"item-info\" class=\"item-info\">
				<h4 class=\"item-h left\">".$staff_data['staff_name']."</h4>
				<a href=\"mailto:".$staff_data['staff_email']."\"><img class=\"left mail\" src=\"../images/ico-mail.png\" alt=\"send e-mail\" /></a>
				<span class=\"right\">".$staff_data['staff_position']."</span>
				<div id=\"item-parag\" class=\"clear\">
				".$staff_data['staff_content']."
				</div>
				</div><!-- End Staff Item -->
			";
		}
		return $this->lowerlevel_staff_content;
	}
	
	public function get_personel_description($people){
	
		$this->db->prepare(
				"
				SELECT
				`staff_meta_description`
				FROM
				`lowerlevel_staff`
				WHERE
				`staff_link` = '$people'
				LIMIT
				1
				;
				"
		);
		$this->db->query();
		while($staff_data = $this->db->fetch('array')){
			$staff_description = $staff_data['staff_meta_description'];
		}
		return $staff_description;
	}
	
	public function get_personel_keywords($people){
		$this->db->prepare(
			"
			SELECT
			`staff_keywords`
			FROM
			`lowerlevel_staff`
			WHERE
			`staff_link` = '$people'
			LIMIT
			1
			;
			"
		);
		$this->db->query();
		while($staff_datas = $this->db->fetch('array')){
			$staff_keywords = $staff_datas['staff_keywords'];
		}
		return $staff_keywords;
	}
	public function get_page_data(){
		//prepare query
		$this->db->prepare
		(
				"
				SELECT
				`page`,
				`title`,
				`description`,
				`keywords`
				FROM
				`page_description`
				WHERE
				`page` = 'staff'
				LIMIT
				1
				;
				"
		);
	
		//execute query
		$this->db->query();
	
		$this->page_data = $this->db->fetch('array');
		return $this->page_data;
	}
}